<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2024/12/24 0024
  Time: 14:50
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <meta charset="UTF-8">
    <title>生产登记复核子页面</title>
    <link rel="stylesheet"  href="/bootstrap/bootstrap-5.3.3-dist/css/bootstrap.min.css" />
    <link rel="stylesheet" href="/css/manufactureCss/e/production_dispatch_order_review_sub.css"></link>
    <style type="text/css">
        #designListBox{
            height: 600px;
        }
        .col1{
            width: 18%;
        }
        .col2{
            width: 31%;
        }
    </style>
</head>
<body style="padding: 15px 50px;background-color: #eeeeee;">
<div class="panel-heading hhead">
    <nav aria-label="breadcrumb">
        <ol class="breadcrumb">
            <span style="color: blue;">您正在做的业务是：</span>
            <li class="breadcrumb-item"><a href="#">生产管理</a></li>
            <li class="breadcrumb-item"><a href="#">内部生产管理</a></li>
            <li class="breadcrumb-item active" aria-current="page">生产登记审核</li>
        </ol>
    </nav>
</div>
<div style="margin-bottom: 2px">
    <div style="display: inline;margin-left: 95%;">
        <button class="btn btn-primary">返回</button>
    </div>
</div> <!-- 此div改用栅格来做 -->
<div id="designListBox">
    <div style="text-align: center">
        <h3>生产登记单</h3>
    </div>
    <div style="padding: 30px">
        <table class="tbl1">
            <tr>
                <td class="col1">派工单编号：</td>
                <td class="col2" id="manufactureId"></td>
                <td class="col1">出库单编号：</td>
                <td class="col2" id=""></td>
            </tr>
            <tr>
                <td class="col1">产品编号：</td>
                <td class="col2" id="productId"></td>
                <td class="col1">产品名称：</td>
                <td class="col2" id="productName"></td>
            </tr>
            <tr>
                <td class="col1">描述：</td>
                <td class="col2" id="productDescribe"></td>
                <td class="col1">数量：</td>
                <td class="col2" id="amount"></td>
            </tr>
        </table>

        <table class="table table-bordered" style="margin: 15px auto;">
            <thead>
            <tr>
                <th>工序名称</th><th>设计工时数</th><th>实际工时数</th>
                <th>设计工时成本（元）</th><th>实际工时成本（元）</th><th>设计物料成本（元）</th>
                <th>实际物料成本（元）</th><th>登记复核</th>
            </tr>
            </thead>
            <tbody id="template">
            <tr>
                <td></td>
                <td>aaaaaaaaaaaaaaaaaaaa</td>
                <td>aaaaaaaaaaaaa</td>
                <td>a</td>
                <td>a</td>
                <td>a</td>
                <td>a</td>
                <td>a</td>
                <td><button class="btn btn-primary" id="btnAdd" data-bs-toggle="modal" data-bs-target="#proRegistraModal">复核</button></td>
            </tr>
            </tbody>

        </table>

        <table class="tbl3">
            <tr>
                <td class="col1">设计工时总成本：</td>
                <td class="col2" id="labourCostPriceSum"></td>
                <td class="col1">设计物料总成本：</td>
                <td class="col2" id="moduleCostPriceSum"></td>
            </tr>
            <tr>
                <td class="col1">实际工时总成本：</td>
                <td class="col2" id="realModuleCostPriceSum"></td>
                <td class="col1">实际物料总成本：</td>
                <td class="col2" id="realLabourCostPriceSum"></td>
            </tr>
            <tr>
                <td class="col1">登记人：</td>
                <td class="col2" id="register"></td>
                <td class="col1">登记时间：</td>
                <td class="col2" id="registerTime"></td>
            </tr>
            <tr>
                <td class="col1">复核人：</td>
                <td class="col2"><input id="checker" type="text" class="txt_under_line"></td>
                <td class="col1">复核时间：</td>
                <td class="col2" id="checkTime"></td>
            </tr>
            <tr>
                <td class="col1">备注：</td>
                <td colspan="3" style="padding-top: 5px">
                    <textarea readonly rows="4" cols="100" id="remark"></textarea>
                </td>
            </tr>

        </table>
    </div>
</div>

<%--<div class="modal fade" id="proRegistraModal" data-bs-backdrop="static" data-bs-keyboard="false" tabindex="-1" aria-labelledby="staticBackdropLabel" aria-hidden="true">--%>
<%--    <div class="modal-dialog modal-xl">--%>
<%--        <div class="modal-content">--%>
<%--            <div class="modal-header">--%>
<%--                <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>--%>
<%--            </div>--%>
<%--            <div class="modal-body">--%>
<%--                <div class="container-fluid">--%>
<%--                    <div id="designListBox">--%>
<%--                        <div style="text-align: center">--%>
<%--                            <h3>生产登记单</h3>--%>
<%--                        </div>--%>
<%--                        <div style="padding: 30px">--%>
<%--                            <form>--%>
<%--                                <table class="tbl1">--%>
<%--                                    <tr>--%>
<%--                                        <td class="col1">派工单编号：</td>--%>
<%--                                        <td class="col2">aaaaaaaaaa</td>--%>
<%--                                        <td class="col1">工序名称：</td>--%>
<%--                                        <td class="col2">组装</td>--%>
<%--                                    </tr>--%>
<%--                                    <tr>--%>
<%--                                        <td class="col1">负责人：</td>--%>
<%--                                        <td class="col2"><input type="text" class="txt_under_line"></td>--%>
<%--                                        <td class="col1">设计工时数：</td>--%>
<%--                                        <td class="col2">aaaaaaaaaa</td>--%>
<%--                                    </tr>--%>
<%--                                    <tr>--%>
<%--                                        <td class="col1">已用工时数：</td>--%>
<%--                                        <td class="col2">2</td>--%>
<%--                                        <td class="col1">本次工时数：</td>--%>
<%--                                        <td class="col2"><input type="text" class="txt_under_line"></td>--%>
<%--                                    </tr>--%>
<%--                                </table>--%>

<%--                                <table class="table table-bordered" style="margin: 15px auto;">--%>
<%--                                    <thead>--%>
<%--                                    <tr>--%>
<%--                                        <th>序号</th><th>物料名称</th><th>物料编号</th><th>设计数量</th>--%>
<%--                                        <th>补充数量</th><th>已使用数量</th><th>本次数量</th>--%>
<%--                                    </tr>--%>
<%--                                    </thead>--%>
<%--                                    <tbody id="template">--%>
<%--                                    <tr>--%>
<%--                                        <td>aaaaaaaaaaaaaaaaaaaa</td>--%>
<%--                                        <td>aaaaaaaaaaaaa</td>--%>
<%--                                        <td>a</td>--%>
<%--                                        <td>a</td>--%>
<%--                                        <td>a</td>--%>
<%--                                        <td>a</td>--%>
<%--                                        <td class="num"><input class="num-input"></td>--%>
<%--                                    </tr>--%>
<%--                                    </tbody>--%>
<%--                                    <tbody id="realData">--%>
<%--                                    <tr>--%>
<%--                                        <td>aaaaaaaaaaaaaaaaaaaa</td>--%>
<%--                                        <td>aaaaaaaaaaaaa</td>--%>
<%--                                        <td>a</td>--%>
<%--                                        <td>a</td>--%>
<%--                                        <td>a</td>--%>
<%--                                        <td>a</td>--%>
<%--                                        <td class="num"><input class="num-input"></td>--%>
<%--                                    </tr>--%>
<%--                                    </tbody>--%>
<%--                                </table>--%>

<%--                                <table class="tbl3">--%>
<%--                                    <tr>--%>
<%--                                        <td class="col1">复核人：</td>--%>
<%--                                        <td class="col2"><input type="text" class="txt_under_line"></td>--%>
<%--                                        <td class="col1">复核时间：</td>--%>
<%--                                        <td class="col2">系统时间</td>--%>
<%--                                    </tr>--%>
<%--                                </table>--%>
<%--                            </form>--%>
<%--                        </div>--%>
<%--                    </div>--%>
<%--                </div>--%>
<%--            </div>--%>
<%--            <div class="modal-footer">--%>
<%--                <button id="btnConcel" class="btn btn-danger" data-bs-dismiss="modal">--%>
<%--                    复核通过<span class="glyphicon glyphicon-remove"></span>--%>
<%--                </button>--%>
<%--                <button id="btnConcel" class="btn btn-danger" data-bs-dismiss="modal">--%>
<%--                    关闭<span class="glyphicon glyphicon-remove"></span>--%>
<%--                </button>--%>
<%--            </div>--%>
<%--        </div>--%>
<%--    </div></div>--%>
<%--</div>--%>
<%--<div class="modal-dialog modal-xl">--%>
<%--    <div class="modal-content">--%>
<%--        <div class="modal-header">--%>
<%--            <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>--%>
<%--        </div>--%>
<%--        <div class="modal-body">--%>
<%--            <div class="container-fluid">--%>
<%--                <div id="designListBox">--%>
<%--                    <div style="text-align: center">--%>
<%--                        <h3>工序物料单</h3>--%>
<%--                    </div>--%>
<%--                    <div style="padding: 30px">--%>
<%--                        <table class="tbl1">--%>
<%--                            <tr>--%>
<%--                                <td class="col1">设计单编号：</td>--%>
<%--                                <td colspan="col2"></td>--%>
<%--                                <td class="col1">工序名称：</td>--%>
<%--                                <td colspan="col2">组装</td>--%>
<%--                            </tr>--%>
<%--                        </table>--%>

<%--                        <table class="table table-bordered" style="margin: 15px auto;">--%>
<%--                            <thead>--%>
<%--                            <tr>--%>
<%--                                <th>序号</th><th>物料名称</th><th>物料编号</th>--%>
<%--                                <th>描述</th><th>本工序数量</th><th>单位</th>--%>
<%--                                <th>单价（元）</th><th>小计（元）</th>--%>
<%--                            </tr>--%>
<%--                            </thead>--%>
<%--                            <tbody id="template">--%>
<%--                            <tr>--%>
<%--                                <td>1</td>--%>
<%--                                <td>aaaaaaaaaaaaa</td>--%>
<%--                                <td>a</td>--%>
<%--                                <td>a</td>--%>
<%--                                <td>a</td>--%>
<%--                                <td>a</td>--%>
<%--                                <td>a</td>--%>
<%--                                <td></td>--%>
<%--                            </tr>--%>
<%--                            </tbody>--%>
<%--                            <tbody id="realData">--%>
<%--                            <tr>--%>
<%--                                <td>1</td>--%>
<%--                                <td>aaaaaaaaaaaaa</td>--%>
<%--                                <td>a</td>--%>
<%--                                <td>a</td>--%>
<%--                                <td>a</td>--%>
<%--                                <td>a</td>--%>
<%--                                <td>a</td>--%>
<%--                                <td></td>--%>
<%--                            </tr>--%>
<%--                            </tbody>--%>
<%--                        </table>--%>
<%--                        </table>--%>
<%--                    </div>--%>
<%--                </div>--%>
<%--            </div>--%>
<%--        </div>--%>
<%--        <div class="modal-footer">--%>

<%--            <button id="btnConcel" class="btn btn-danger" data-bs-dismiss="modal">--%>
<%--                关闭<span class="glyphicon glyphicon-remove"></span>--%>
<%--            </button>--%>
<%--        </div>--%>
<%--    </div>--%>
<%--</div>--%>
<%--</div>--%>

<script type="text/javascript" src="/js/jquery-3.7.0.min.js"></script>
<script type="text/javascript" src="/bootstrap/bootstrap-5.3.3-dist/js/bootstrap.bundle.js"></script>
<script type="text/javascript">
    $(function () {
        initialTable();
        // 初始化时间
        setInterval(updateDateTime, 1000);
    })
    function initialTable() {
        let id = sessionStorage.getItem("id");
        $.ajax({
            url:"/m-manufacture/selectById?id="+id,
            type:"get",
            dataType:"json",
            success:function (mManufacture) {
                $("#manufactureId").text(mManufacture.manufactureId);
                $("#productId").text(mManufacture.productId);
                $("#productName").text(mManufacture.productName);
                $("#amount").text(mManufacture.amount);
                $("#designer").text(mManufacture.designer);
                $("#labourCostPriceSum").text(mManufacture.labourCostPriceSum);
                $("#moduleCostPriceSum").text(mManufacture.moduleCostPriceSum);
                $("#register").text(mManufacture.register);
                $("#registerTime").text(mManufacture.registerTime);
                $("#remark").text(mManufacture.remark);
                initialTemplate(id);
            }

        })
    }
    function initialTemplate(id){
        $.ajax({
            type: "GET",
            url: "/m-procedure/selectArrByParentId?id="+id,
            dataType: "json",
            success: function (data){
                $("#template").empty()
                let procedure ;
                if(data!=null){
                    $.ajax({
                        type: "GET",
                        url: "/m-proceduring/selectArrByParentId?id="+id,
                        dataType: "json",
                        async: false,
                        success: function (proceduring){
                            procedure = proceduring;
                        }
                    })
                }

                for (let i = 0; i < data.length; i++) {

                    let moduleSubtotal = 0;
                    data[i].moduleSubtotal === null ? moduleSubtotal = 0 : moduleSubtotal = data[i].moduleSubtotal;
                    let tr = $("<tr></tr>");
                    // let td0 = $("<td id='"+data[i].id+"'></td>").text(data[i].detailsNumber);
                    let td1 = $("<td></td>").text(data[i].procedureName);
                    let td2 = $("<td></td>").text(data[i].labourHourAmount);
                    let td3 = "";
                    if (procedure[0]!= undefined && data[i].procedureId == procedure[0].procedureId){
                        let realLabourHourAmount = data[i].realLabourHourAmount==null?0:data[i].realLabourHourAmount;
                        td3 = $("<td></td>").text(parseFloat(realLabourHourAmount)+parseFloat(procedure[0].labourHourAmount));
                    }else{
                        td3 = $("<td></td>").text(data[i].realLabourHourAmount);
                    }
                    let td4 = $("<td></td>").text(data[i].subtotal);
                    let td5 = ""
                    if (procedure[0]!= undefined && data[i].procedureId == procedure[0].procedureId){
                        let realSubtotal = data[i].realSubtotal==null?0:data[i].realSubtotal;
                        td5 = $("<td></td>").text(parseFloat(realSubtotal)+parseFloat(procedure[0].subtotal));
                    }else{
                        td5 = $("<td></td>").text(data[i].realSubtotal);
                    }
                    let td6 = $("<td></td>").text(data[i].moduleSubtotal);
                    let td7 = "";
                    if (procedure[0]!= undefined && data[i].procedureId == procedure[0].procedureId){
                        let realModuleSubtotal = data[i].realModuleSubtotal==null?0:data[i].realModuleSubtotal;
                        let moduleSubtotal = "";
                        $.ajax({
                            type: "GET",
                            url: "/m-procedure-moduling/selectModuleSubtotalByProcedureId?id=" + procedure[0].id,
                            dataType: "json",
                            async: false,
                            success: function (Subtotal) {
                                moduleSubtotal = Subtotal;
                            }
                        })
                        td7 = $("<td></td>").text(parseFloat(realModuleSubtotal)+parseFloat(moduleSubtotal));
                    }else{
                        td7 = $("<td></td>").text(data[i].realModuleSubtotal);
                    }
                    let obj = data[i];
                    let td8 =""
                    if (procedure[0]!= undefined && data[i].procedureId == procedure[0].procedureId){
                        td8 = $("<td></td>").html("<a href='javascript:audit("+obj.id+");' class='btn btn-primary' >审核</a>")
                    }else{
                        $.ajax({
                            type: "GET",
                            url: "/m-procedure/selectOneById?id="+data[i].id,
                            dataType: "json",
                            async: false,
                            success: function (mProcedure){
                                if(mProcedure.procedureFinishTag == 2){
                                    if(mProcedure.procedureTransferTag == 1){
                                        td8 = $("<td></td>").html("<a href='javascript:handoverAudits("+obj.id+");' class='btn btn-primary' >审核</a>")
                                    }
                                }
                            }
                        })
                    }
                    tr.append(td1,td2,td3,td4,td5,td6,td7,td8);
                    $("#template").append(tr);
                }
            }
        })
    }
    function audit(id) {
        let flag = sessionStorage.getItem("flag")
        if (flag == 1){
            alert("您已提交，请勿重复提交")
            return
        }
        let checker = $("#checker").val();
        if (checker == ""){
            alert("请输入审核人")
            return
        }
        let remark = $("#remark").val()
        $.ajax({
            type: "GET",
            url: "/m-procedure/selectOneById?id="+id,
            dataType: "json",
            success: function (data){
                console.log(data)
                let procedureFinishTag = data.procedureFinishTag;
                let procedureTransferTag = data.procedureTransferTag;
                if (procedureFinishTag == 0){
                    if (procedureTransferTag == 2){
                        //登记审核
                        let a = $("#template").find("a")
                        let realLabourHourAmount = a.parent().parent().find("td:eq(2)").text()
                        let realSubtotal = a.parent().parent().find("td:eq(4)").text()
                        let realModuleSubtotal = a.parent().parent().find("td:eq(6)").text()
                        let json = {
                            id:id,
                            realLabourHourAmount:realLabourHourAmount,
                            realSubtotal:realSubtotal,
                            realModuleSubtotal:realModuleSubtotal,
                            procedureFinishTag:0,
                            procedureTransferTag:0,
                            checker:checker,
                            remark:remark
                        }
                        $.ajax({
                            type: "POST",
                            url: "/m-proceduring/registrationAudit",
                            data: JSON.stringify(json),
                            contentType: "application/json",
                            success: function (data2){
                                if(data2){
                                   alert("审核成功")
                                   initialTable();
                                   sessionStorage.setItem("flag",1)
                                }else{
                                    alert("审核失败")
                                }
                            }
                        })
                    }
                }else if (procedureFinishTag == 1){
                    if (procedureTransferTag == 2){
                        //完成审核
                        let a = $("#template").find("a")
                        let realLabourHourAmount = a.parent().parent().find("td:eq(2)").text()
                        let realSubtotal = a.parent().parent().find("td:eq(4)").text()
                        let realModuleSubtotal = a.parent().parent().find("td:eq(6)").text()
                        let json = {
                            id:id,
                            realLabourHourAmount:realLabourHourAmount,
                            realSubtotal:realSubtotal,
                            realModuleSubtotal:realModuleSubtotal,
                            procedureFinishTag:1,
                            procedureTransferTag:0,
                            checker:checker,
                            remark:remark
                        }
                        $.ajax({
                            type: "POST",
                            url: "/m-proceduring/registrationAudit",
                            data: JSON.stringify(json),
                            contentType: "application/json",
                            success: function (data2){
                                if(data2){
                                    alert("审核成功")
                                    initialTable()
                                    sessionStorage.setItem("flag",1)
                                }else{
                                    alert("审核失败")
                                }
                            }
                        })
                    }

                }
            }
        })
    }
    function handoverAudits(id) {
        let flag = sessionStorage.getItem("flag")
        if (flag == 1) {
            alert("您已提交，请勿重复提交")
            return
        }
        let checker = $("#checker").val();
        if (checker == "") {
            alert("请输入审核人")
            return
        }
        let remark = $("#remark").val()
        let json = {
            id:id,
            procedureFinishTag:1,
            procedureTransferTag:1,
            checker:checker,
            remark:remark
        }
        $.ajax({
            type: "POST",
            url: "/m-proceduring/handoverAudits",
            data: JSON.stringify(json),
            contentType: "application/json",
            success: function (data2){
                if(data2){
                    alert("审核成功")
                    initialTable()
                    sessionStorage.setItem("flag",1)
                }else{
                    alert("审核失败")
                }
            }
        })
    }
    function updateDateTime(){
        let date = new Date();
        let year = date.getFullYear();
        let month = (date.getMonth() + 1).toString().padStart(2, '0');
        let day = date.getDate().toString().padStart(2,'0');
        let hours = date.getHours().toString().padStart(2,'0');
        let minutes = date.getMinutes().toString().padStart(2,'0');
        let seconds = date.getSeconds().toString().padStart(2,'0');
        let dateTimeStr = year+"-"+month+"-"+day+" "+hours+":"+minutes+":"+seconds;
        $("#checkTime").text(dateTimeStr);
    }
</script>
</body>
</html>